<?php
/**
 * Created by PhpStorm.
 * User: 小灰灰
 * Date: 2023-11-17
 * Time: 10:41:42
 * Info:
 */

if ( ! function_exists('cmf_get_cate_id')) {
    /**
     * 获取栏目id
     * @return void
     */
    function cmf_get_cate_id()
    {

    }
}

if ( ! function_exists('get_tree')) {
//递归返回树形菜单数据
    function get_tree($data, $pId, $deep = 0)
    {
        $tree = [];
        foreach ($data as $k => $v) {
            if ($v['pid'] == $pId) {
                //父亲找到儿子
                $deep++;
                $v['sub'] = get_tree($data, $v['id'], $deep);
                $tree[]   = $v;
            }
        }

        return array_values($tree);
    }
}

if ( ! function_exists('is_spider')) {
// 检测用户代理是否为搜索引擎蜘蛛
    function is_spider()
    {
        $userAgent = $_SERVER['HTTP_USER_AGENT'];
        $bots      = [
            '/bot|crawl|slurp|spider|crawling|indexer|pinger|archive|find|other/i', // 常见的蜘蛛用户代理
        ];

        foreach ($bots as $bot) {
            if (preg_match($bot, $userAgent)) {
                return true;
            }
        }

        return false;
    }
}
